<template>
  <div class="loginDiv">
    <div class="loginBox">
      <svg-icon name="menu-logo" class="menuLogo" style="font-size: 60px" />
      <a-form
        :model="formState"
        name="normal_login"
        class="login-form"
        @finish="onFinish"
        @finishFailed="onFinishFailed"
      >
        <p class="DL">登录</p>
        <a-form-item
          label=""
          name="username"
          :rules="[{ required: true, message: '账号不能为空!' }]"
        >
          <a-input
            size="large"
            v-model:value="formState.username"
            aria-placeholder="请输入用户账号"
          >
            <template #prefix>
              <UserOutlined class="site-form-item-icon" />
            </template>
          </a-input>
        </a-form-item>

        <a-form-item
          label=""
          name="password"
          :rules="[{ required: true, message: '登录密码不能为空!' }]"
        >
          <a-input-password
            size="large"
            v-model:value="formState.password"
            aria-placeholder="请输入登录密码"
          >
            <template #prefix>
              <LockOutlined class="site-form-item-icon" />
            </template>
          </a-input-password>
        </a-form-item>

        <a-form-item>
          <a-button
            :disabled="isSubmitting"
            size="large"
            style="width: 100%"
            class="orgin_but"
            type="primary"
            html-type="submit"
          >
            登录
          </a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>
    <script setup>
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
import { login } from '@/api/user.js'
import { message } from 'ant-design-vue'
import { useRouter, useRoute } from 'vue-router'
import { useCounterStore } from '@/stores/index.js'
import { encryptMd5 } from '@/utils/index.js'
const store = useCounterStore()
// 路由
const router = useRouter()
const route = useRoute()
const query = route.query
console.log(route)
console.log(query)
if (query && query.type == 'unlogin') {
  message.error('已于异地登录，请重新登录')
}

import { reactive, ref, computed } from 'vue'
const formState = reactive({
  username: '',
  password: '',
  remember: true,
})

const isSubmitting = ref(false)
const onFinish = (values) => {
  isSubmitting.value = true
  console.log('Success:', values)
  login(values.username, encryptMd5(values.password))
    .then((res) => {
      console.log(res)
      isSubmitting.value = false
      store.settingUserInfo({
        token: res.data.token,
        userInfo: res.data.user,
      })
      router.push('/recharge')
    })
    .catch(() => {
      console.log('错误')
      isSubmitting.value = false
    })
}

const onFinishFailed = (errorInfo) => {
  console.log('Failed:', errorInfo)
}
</script>
    <style scoped lang="scss">
.loginDiv {
  display: flex;
  width: 100%;
  height: 100%;
  background-size: 100% 100%;
  position: absolute;
  top: 0;
  left: 0;
  align-items: center;
  .loginBox {
    background: #fff;
    width: 400px;
    margin-left: 200px;
    position: relative;
    padding: 20px 30px;
    .menuLogo {
      position: absolute;
      top: -80px;
      left: 170px;
    }
    .DL {
      font-size: 20px;
      font-weight: bold;
      text-align: center;
    }
    .showtip :hover {
      color: #ff6a00;
    }
  }
}
</style>